#include <bits/stdc++.h>
using namespace std;
int pile[100];
void solve(int f, int p){
    pile[p] += f;
    int l, r;
    cin >> l;
    if(l != -1) solve(l, p-1);
    cin >> r;
    if(r != -1) solve(r, p+1);
}

int main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    int T = 0; int r;
    while(cin >> r && r!=-1){
        memset(pile, 0, sizeof(pile));
        solve(r, 50);
        ++T;
        cout << "Case " << T << ":\n";
        bool first = true;
        for (auto i:pile){
            if(i){
                if(first){first = false;}
                else cout << " ";
                cout << i;
            }
        }
        cout << "\n\n";
    }
    return 0;
}